var userList;
$(function(){
	//渲染加载表格
	if($("#userList").length>0){
        userList = $.fn.bsgrid.init('userList', {
            url:'../../testApi/userList.php',               //数据地址
            // autoLoad: false,
            pageSizeSelect: true,
            pageSize: 10,
            stripeRows: true,
            displayBlankRows: false
        });
    }
    
    //加载省市三级联动
    if($(".provinceList").length>0){
        provinceList.init($(".provinceList"));
    }
    //上传头像设置
    var options ={
        thumbBox: '.thumbBox',
        spinner: '.spinner',
        imgSrc: $(".uploadImg").attr("src")
    };
    if($(".imageBox").length>0){
        var cropper = $('.imageBox').cropbox(options);
    }
    $('#upload-file').on('change', function(){
        var reader = new FileReader();
        reader.onload = function(e) {
            options.imgSrc = e.target.result;
            cropper = $('.imageBox').cropbox(options);
        }
        reader.readAsDataURL(this.files[0]);
        this.files = [];
    })
    $('#btnCrop').on('click', function(){
        var img = cropper.getDataURL();
        $('.cropped').html('<img src="'+img+'" align="absmiddle" style="width:120px;margin-top:10px;"><p>120px*120px</p>');
    })
    $('#btnZoomIn').on('click', function(){
        cropper.zoomIn();
    })
    $('#btnZoomOut').on('click', function(){
        cropper.zoomOut();
    })
    $('#headImgBox').on('okHide', function(e){
        var img = cropper.getDataURL();
        $("#headImg").val(img);
        $(".uploadImg").attr("src", img);
    })
})

//user表格相关方法
var user={
    //认证标识
    authentication:function(record, rowIndex, colIndex, options){
        var authentication=userList.getRecordIndexValue(record, 'authentication');
        var id=userList.getRecordIndexValue(record, 'id');
        if(authentication==1) return '<a href="userAuthDetails.html?id=' + id + '" class="sui-text-success">已认证（查看）</a>';
        else if(authentication==0) return '<span class="sui-text-disabled">未认证</span>';
    },
    //表格操作
    operate:function(record, rowIndex, colIndex, options) {
        var id=userList.getRecordIndexValue(record, 'id');
        var operate='<a href="userEdit.html?id=' + id + '">编辑</a> '+
                    '<a href="userMoney.html?id=' + id + '">现金</a> '+
                    '<a href="javascript:;" onclick="user.del(' + id + ')">删除</a> ';
        return operate;
    },
    //搜索
    search:function(){
        var form=$("#seach").serializeArray();
        userList.search(form);
    },
    //删除单个账号
    del:function(id){
        table.del({
            "id":id,
            "url":'../../testApi/dels.php'
        })
    },
    //删除勾选账号
    delCheck:function(){
        var ids = userList.getCheckedValues("id");
        table.delCheck({
            "ids":ids,
            "url":'../../testApi/dels.php'
        })   
    }
}
//编辑账户
$("#userEdit").validate({
    rules:{
        phone:{required:true,mobile:true},
        password:{required:true},
        email:{email:true}
    }
})


